﻿using Microsoft.WindowsAzure.Storage.Table;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Wams.Admin
{
    public class WamsInstanceState
    {
        public int InstanceId;
        public string DeploymentId;
        public DateTimeOffset LastTimespan;
        public bool IsBusy;
        public InstanceStatus Status;

        public string DeploymentInstanceId { get { return string.Format("{0}_{1}", DeploymentId, InstanceId); } }
    }
    public class WamsSiteState
    {
        public int Id;
        public string DeploymentInstanceId;
        public SiteStatus Status;
    }

    public enum InstanceStatus
    {
        Init = 0,
        Starting = 1,
        SettingsRefreshInProgress = 2,
        ShuttingDown = 3,
        Error = 4,
        Active = 5,
        Stale = 6,
        Waiting = 7
    }
    public enum SiteStatus
    {
        Init = 0,
        ContentSyncInProgress = 1,
        SettingsSyncInProgress = 2,
        Active = 3,
        Error = 4,
        Stale = 5,
        Waiting = 6
    }

    internal class WamsInstanceStateEntity : TableEntity
    {
        public string DeploymentId
        { get { return PartitionKey; } }
        public int InstanceId
        { get { int rowKey; int.TryParse(RowKey, out rowKey); return rowKey; } }

        public bool IsBusy { get; set; }
        public DateTime LastSettingsRefresh { get; set; }
        public int UpdateDomain { get; set; }

        public int InnerStatus { get; set; }
        public InstanceStatus Status
        { get { return (InstanceStatus)InnerStatus; } }
    }

    internal class WamsSiteStateEntity : TableEntity
    {
        public int Id
        { get { return int.Parse(RowKey); } }

        public string DeploymentInstanceId
        { get { return PartitionKey; } }

        public int InnerStatus { get; set; }
        public SiteStatus Status
        { get { return (SiteStatus)InnerStatus; } }
    }
}
